<?php
function search()
{	
$brand=$_POST['brand'];
if(isset($_POST['model_select']))
$model_id=explode(" ",$_POST['model_select']);
$model=$model_id[0];
$id=$model_id[1];
$pick_from=$_POST['datepick_from'];
$pick_to=$_POST['datepick_to'];

			//elegxos diathesimotitas imerominiwn
			$orders_data=mysql_query("SELECT * FROM orders WHERE bike_id='$id'") or die(mysql_error());
			while($orders_info=mysql_fetch_array($orders_data))
			{
				$from=$orders_info['date_from'];
				$to=$orders_info['date_to'];
				$date_from=strtotime($from);
				$date_to=strtotime($to);
				$date_pick_from=strtotime($pick_from);
				$date_pick_to=strtotime($pick_to);
				if($date_from-$date_pick_to<=0 && $date_to-$date_pick_from>=0)
					{
						echo"We are sorry. The date is not available for this bike"."<br>";
						echo"The bike is reserved between " . $from . " and " . $to . "<br>";
						echo"<a href='search.php'>Search Again!!!</a>";
						die();
					}
			}


	//emfanisi search result
	if(isset($brand)&&isset($model))
	{
		$data=mysql_query("SELECT * FROM bike WHERE brand='$brand' AND model='$model' AND id='$id'") or die(mysql_error());
		$dir="http://localhost/bike_rental/pics/bikes/";
		while($info=mysql_fetch_array($data))
		{	$id=$info['id'];
			$brand=$info['brand'];
			$model=$info['model'];
			$color=$info['color'];
			$price=$info['price_per_day'];
			$year_of_make=$info['year_of_make'];
			$description=$info['description'];
			$photo_path=$info['photo_path'];
			$from=$info['date_from'];
			$to=$info['date_to'];
			$complete_path=$dir.$photo_path;

						//apostoli dedomenwn sto order confirm
						echo" <div class='individual'>
					  	<img src='$complete_path'>
							<div class='bike_details'>
								<ul>
									<li>$brand</li>
									<li>$model</li>
									<li>$color</li>
									<li>Daily Price: $price Euros</li>
									<li>$year_of_make</li>
									<li>$description</li>
									From:$pick_from<br>
									To:$pick_to
								</ul>
								<form action='order.php' method='post'>
									<input type='hidden' value='$id', name='id'>
									<input type='hidden' value='$brand' name='brand'>
									<input type='hidden' value='$model' name='model'>
									<input type='hidden' value='$color' name='color'>
									<input type='hidden' value='$price' name='price'>
									<input type='hidden' value='$year_of_make' name='year_of_make'>
									<input type='hidden' value='$description' name='description'>
									<input type='hidden' value='$pick_from' name='date_pick_from'>
									<input type='hidden' value='$pick_to' name='date_pick_to'>"; 
									if(isset($_SESSION['username']))
									echo"<input type='submit' value='ORDER NOW!'>";
									echo"
								</form>							
							</div>
						</div>";	
					}	
			}
	else 
	{
		echo"We are sorry, the requested bike does not exist. Search again!";
		echo"<meta HTTP-EQUIV='REFRESH' content='4; url=Search.php'> </meta>";
	}

}
?>